package com.rfs.design.templatemethod;


import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
* @author: rfs
* @create: 2021/8/17
* @description: vip用户
**/
@Service("VipUserCart")
public class VipUserCart extends AbstractCart {
    @Override
    protected CartTypeEnum getCartType(){
        return CartTypeEnum.VIP;
    }
    @Override
    protected void processCouponPrice(long userId, Item item) {
        if (item.getQuantity() > 2) {
            item.setCouponPrice(item.getPrice().multiply(BigDecimal.valueOf(item.getQuantity() - 2)).multiply(BigDecimal.valueOf(100 - Db.getUserCouponPercent(userId)).divide(new BigDecimal("100"))));
        }else {
            item.setCouponPrice(BigDecimal.ZERO);
        }
    }
    @Override
    protected void processDeliveryPrice(long userId, Item item) {
        System.out.print("VIP用户计算运费");
        item.setDeliveryPrice(item.getPrice().multiply(BigDecimal.valueOf(item.getQuantity())).multiply(new BigDecimal("0.1")));
    }
}
